/*
 * adf4371.c
 *
 *  Created on: 2020��7��11��
 *      Author: wrangler
 */
#include <SI_C8051F310_Register_Enums.h>

#define CS_1 (P1 |= 0x04)
#define CS_0 (P1 &= ~0x04)

#define DAT_1 (P1 |= 0x08)
#define DAT_0 (P1 &= ~0x08)

#define CLK_1 (P1 |= 0x10)
#define CLK_0 (P1 &= ~0x10)

#define CE_1 (P1 |= 0x20)
#define CE_0 (P1 &= ~0x20)

unsigned char reg_var[128] =
{
		0x10,0x40,
		0x11,0x00,
		0x12,0x40,
		0x14,0xAA,
		0x15,0xAA,
		0x16,0x2A,
		0x17,0x05,
		0x18,0x00,
		0x19,0x03,
		0x1a,0x00,
		0x1b,0x00,
		0x1c,0x00,
		0x1d,0x00,
		0x1e,0x48,
		0x1f,0x01,
		0x20,0x14,
		0x21,0x00,
		0x22,0x00,
		0x23,0x00,
		0x24,0x080,
		0x25,0x13,
		0x26,0x19,
		0x27,0x0CD,
		0x28,0x083,
		0x2a,0x00,
		0x2b,0x10,
		0x2c,0x44,
		0x2d,0x11,
		0x2e,0x12,
		0x2f,0x094,
		0x30,0x32,
		0x31,0x02,
		0x32,0x04,
		0x33,0x23,
		0x34,0x086,
		0x35,0x0FF,
		0x36,0x30,
		0x37,0x00,
		0x38,0x00,
		0x39,0x07,
		0x3a,0x55,
		0x3d,0x00,
		0x3e,0x0C,
		0x3f,0x080,
		0x40,0x50,
		0x41,0x28,
		0x42,0x00,
		0x43,0x00,
		0x44,0x00,
		0x45,0x00,
		0x46,0x00,
		0x47,0xC0,
		0x52,0xF4,
		0x6c,0x00,
		0x6e,0x00,
		0x6f,0x00,
		0x70,0x0E3,
		0x71,0x01,
		0x72,0x32,
		0x73,0x00,
		0x79,0x00,
		0x7a,0x00,
		0x7b,0x00,
		0x7c,0x00
};

void ConfigReset()
{
	CE_1;

	CS_1;
	CLK_1;
	DAT_1;
}


void ConfigReg(unsigned int reg,unsigned char var)
{
	unsigned char index;
	reg &= ~0x8000;
	CS_0;

	for(index=0;index<16;index++)
	{
		if((reg & 0x8000) == 0x8000)
			DAT_1;
		else DAT_0;
		CLK_0;
		CLK_1;

		reg = (reg << 1);
	}

	for(index=0;index<8;index++)
	{
		if((var & 0x8000) == 0x8000)
			DAT_1;
		else DAT_0;
		CLK_0;
		CLK_1;

		var = (var << 1);
	}

	CS_1;
}

void ConfigADF4371()
{
	unsigned char index;
	ConfigReg(0x00,0x00);
	ConfigReg(0x01,0x80);//single byte mode

	for(index = 0;index<128;index=index+2)
		ConfigReg(reg_var[126 - index],reg_var[127-index]);
}





